<?php
class SP_Config_Configurator
{
	protected static $SP_CONFIGS=array();
	protected static $ROOT_DIR;
	protected static $INCLUDE_DIR;

	public static function get($name, $default = null)
	{
		return isset(self::$SP_CONFIGS[$name]) ? self::$SP_CONFIGS[$name] : $default;
	}

	public static function __get($name)
	{
		return self::get($name);
	}
	
	public static function has($name)
	{
		return array_key_exists($name, self::$SP_CONFIGS);
	}
	
	public static function set($name, $value)
	{
		self::$SP_CONFIGS[$name]=$value;
	}
	
	public function getAll()
	{
		return self::$SP_CONFIGS;
	}
	
	public static function clear()
	{
		self::$SP_CONFIGS = array();
	}
	
	public static function setRootDir($value)
	{
		self::$ROOT_DIR = $value;
	}
	
	public static function getRootDir()
	{
		return self::$ROOT_DIR.'/';
	}
	
	public static function setIncludeDir($value)
	{
		self::$INCLUDE_DIR = $value;
	}
	
	public static function getIncludeDir()
	{
		return self::$INCLUDE_DIR.'/';
	}
	
	public static function readConfig($name,$path)
	{
		$config = new SP_Config_Configuration;
		if($config->read($path))
		{
			self::set($name, $config);
			return true;
		}
		if($config->read(self::getIncludeDir().$path))
		{
			self::set($name, $config);
			return true;
		}
		return false;
	}
}